/*
 * Copyright: (C) 2014 EAST fulinux <fulinux@sina.com>
 */
#include <stdio.h>
#include <stdlib.h>
#include <linked_list.h>

int comp_func(list_node_t *list, void *data)
{
    if(list->data == data){
        return 1;
    }

    return 0;
}

/*
 * 主函数 
 */
int main (int argc, char **argv)
{
    list_node_t *list;
    list_node_t *p;

    list = list_create_new("fulinux");

    if(!list_insert_after(list, "hello")){
        perror("list_insert_after");
    } 

    if(!list_insert_end(list, "world")){
        perror("list_insert_end");
    }

    if(!(list = list_insert_beginning(list, "Oh!"))){
        perror("list_insert_beginning");
    }

    for(p = list; p != NULL; p = p->next)
        printf("%s ", (char *)p->data);
    printf("\n");

    /* 删除"Oh!"节点 */
    list_remove_by_data(&list, "Oh!");

    for(p = list; p != NULL; p = p->next)
        printf("%s ", (char *)p->data);
    printf("\n");

    /* 获取"world"节点地址, 再删除它 */

    p = list;
    if(!(p = list_find(p, comp_func, "hello"))){
        perror("list_find");
    }else{
        printf("find: %s\n", (char *)p->data);
    }

    return 0;
} /* ----- End of main() ----- */

